home *** CD-ROM | disk | FTP | other *** search
- #ifndef __THREADMANAGER__
- #define __THREADMANAGER__
- #pragma once
-
- #include "Module.h"
-
- #include <Threads.h>
- #include <Gestalt.h>
-
- //--------------------------------------------------------------------------------
-
- class ThreadManager : public TModule
- {
- DeclareClassSingle(ThreadManager, TModule);
-
- protected:
- static ThreadManager* gThreadManager;
- static long gThreadGestalt;
- static long gThreadCount;
- static ThreadTaskRef gTaskRef;
-
- public:
- static ThreadManager& GetThreadManager();
-
- ThreadManager();
- virtual ~ThreadManager();
- virtual bool Validate();
- virtual void Initialize(void);
-
- static ThreadID NewThreadID(ThreadStyle threadStyle,
- ThreadEntryProcPtr threadEntry,
- void * threadParam,
- Size stackSize,
- ThreadOptions options,
- void ** threadResult);
- static void* DisposeThreadID(ThreadID threadToDump);
- static void* RecycleThreadID(ThreadID threadToDump);
-
- static inline ThreadTaskRef GetTaskRef() { return gTaskRef; }
-
- static inline bool ThreadManagerPresent() { return TestBit(gThreadGestalt, gestaltThreadMgrPresent); }
- static inline bool SpecificMatchSupport() { return TestBit(gThreadGestalt, gestaltSpecificMatchSupport); }
- static inline bool ThreadsLibraryPresent() { return TestBit(gThreadGestalt, gestaltThreadsLibraryPresent); }
-
- protected:
- static pascal void ThreadCreatedProc(ThreadID threadCreated);
- static pascal void ThreadDeletedProc(ThreadID threadDeleted);
- static pascal ThreadID ThreadScheduleProc(SchedulerInfoRecPtr schedulerInfo);
- };
-
- //--------------------------------------------------------------------------------
-
- #if !qDebug
-
- inline ThreadManager& ThreadManager::GetThreadManager()
- {
- return *gThreadManager;
- }
-
- #endif
-
- //--------------------------------------------------------------------------------
-
- #endif __THREADMANAGER__
-